package com.jeesite.modules.exam.quota.service;

import com.alibaba.fastjson.JSONArray;
import com.jeesite.common.config.Global;
import com.jeesite.common.entity.Page;
import com.jeesite.common.idgen.IdGen;
import com.jeesite.common.service.CrudService;
import com.jeesite.common.service.ServiceException;
import com.jeesite.modules.backlog.service.DcSupBacklogService;
import com.jeesite.modules.common.dao.SysBasicDao;
import com.jeesite.modules.common.entity.SysBasicUser;
import com.jeesite.modules.exam.assessment.entity.DcSupExamInfo;
import com.jeesite.modules.exam.quota.dao.DcSupExamTargetAuditDao;
import com.jeesite.modules.exam.quota.entity.DcSupExamQuota;
import com.jeesite.modules.exam.quota.entity.DcSupExamQuotaInfo;
import com.jeesite.modules.exam.quota.entity.DcSupExamQuotaOrg;
import com.jeesite.modules.exam.quota.entity.DcSupExamSumQuotaInfo;
import com.jeesite.modules.exam.socreResult.entity.DcSupExamOrgSelect;
import com.jeesite.modules.exam.socreResult.service.DcSupExamOrgSelectService;
import com.jeesite.modules.file.entity.FileUpload;
import com.jeesite.modules.file.service.FileUploadService;
import com.jeesite.modules.home.entity.cuibanDto;
import com.jeesite.modules.msg.entity.content.PcMsgContent;
import com.jeesite.modules.msg.utils.MsgPushUtils;
import com.jeesite.modules.sys.entity.User;
import com.jeesite.modules.sys.utils.EmpUtils;
import com.jeesite.modules.sys.utils.UserUtils;
import com.jeesite.modules.task.action.dao.DcSupTaskActionDao;
import com.jeesite.modules.task.deploy.entity.OfficeUser;
import com.jeesite.modules.yzw.entity.MsgDetail;
import com.jeesite.modules.yzw.service.LehandYzwPushTask;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.ui.Model;
import org.springframework.util.CollectionUtils;

import javax.annotation.Resource;
import java.util.*;

import static com.jeesite.common.web.http.ServletUtils.renderResult;

/**
 * 指标审核Service
 *
 * @author cjs
 * @version 2022-05-31
 */
@Service
@Transactional(readOnly = false)
public class DcSupExamTargetAuditService extends CrudService<DcSupExamTargetAuditDao, DcSupExamQuotaInfo> {
    @Autowired
    private DcSupExamTargetAuditDao targetAuditDao;

    @Autowired
    private DcSupExamQuotaService dcSupExamQuotaService;
    @Autowired
    private DcSupExamSumQuotaInfoService dcSupExamSumQuotaInfoService;
    @Autowired
    private DcSupTaskActionDao dcSupTaskActionDao;
    @Autowired
    private DcSupExamQuotaInfoService dcSupExamQuotaInfoService;
    @Autowired
    private DcSupExamQuotaOrgService dcSupExamQuotaOrgService;
    @Resource
    private FileUploadService fileUploadService;
    @Autowired
    private DcSupExamOrgSelectService dcSupExamOrgSelectService;
    @Autowired
    private LehandYzwPushTask lehandYzwPushTask;
    @Autowired
    private DcSupBacklogService dcSupBacklogService;
    /**
     * 查询分页数据
     *
     * @param dcSupExamInfo 查询条件
     * @return
     */
    public Page<DcSupExamInfo> findPage(DcSupExamInfo dcSupExamInfo) {
        int pageNo = 1;
        if (null == dcSupExamInfo.getPageNo() || dcSupExamInfo.getPageNo() == 0) {
            pageNo = 1;
        } else {
            pageNo = dcSupExamInfo.getPageNo();
        }
        int pageSize = dcSupExamInfo.getPageSize();
        int start = (pageNo - 1) * pageSize;
        Page<DcSupExamInfo> page = dcSupExamInfo.getPage();
        dcSupExamInfo.setPageSize(pageSize);
        dcSupExamInfo.setPageNo(pageNo);
        List<DcSupExamInfo> list = targetAuditDao.findPage(dcSupExamInfo);
        //Integer total = targetAuditDao.findPageTotal(dcSupExamInfo);
       // page.setCount(total);
        page.setList(list);
       // page.setPageNo(dcSupExamInfo.getPageNo());
      //  page.setPageSize(dcSupExamInfo.getPageSize());
        return page;
    }

    /**
     * 单项指标考核细则审核页面查询被考核单位
     */
    public List<Map<String, String>> exameOrgListData(String createOrgName, String examYear,String examId) {
        return targetAuditDao.exameOrgListData(createOrgName, examYear,examId);
    }

    /**
     * 单项指标考核细则审核列表数据
     */
    public int dcSupExamScoreDataTotal(DcSupExamSumQuotaInfo dcSupExamSumQuotaInfo) {
        return targetAuditDao.dcSupExamScoreDataTotal(dcSupExamSumQuotaInfo);
    }

    /**
     * 单项/关键指标考核报送通知列表页数据
     */
    /*public Page<DcSupExamQuotaInfo> dcSupExamZBData(DcSupExamQuotaInfo dcSupExamQuotaInfo) {
        Page page = new Page();
        List<DcSupExamQuotaInfo> list = targetAuditDao.dcSupExamZBData(dcSupExamQuotaInfo);
        page.setCount(0);
        page.setList(list);
        page.setPageNo(dcSupExamQuotaInfo.getPageNo());
        page.setPageSize(dcSupExamQuotaInfo.getPageSize());
        return page;
    }*/
    public List<DcSupExamQuotaInfo> dcSupExamZBData(DcSupExamQuota dcSupExamQuota) {
        return targetAuditDao.dcSupExamZBData(dcSupExamQuota);
    }

    //审核退回功能
    public void exameSendBack(DcSupExamQuota dcSupExamQuota) {
        List<DcSupExamQuota> list = dcSupExamQuotaService.findList(dcSupExamQuota);
        if (CollectionUtils.isEmpty(list)) {
            throw new ServiceException("当前指标为空，不能退回！");
        }
        list.stream().forEach(x -> {
            x.setUpdateBy(UserUtils.getUser().getUserCode());
            x.setUpdateDate(new Date());
            x.setSubmitStatus("3");
            dcSupExamQuotaService.update(x);
        });

//        PcMsgContent msg = new PcMsgContent();
//        msg.setTitle("提示信息");
        DcSupExamQuota dcSupExamQuota1 = list.get(0);
        User user = UserUtils.get(dcSupExamQuota1.getCreateBy());
//        msg.setContent("您有一个关键指标报送被驳回，请及时查看");
//        msg.addButton("报送", "/a/quota/dcSupExamQuota?id="+dcSupExamQuota1.getId()+"&quotaGroup="+dcSupExamQuota.getQuotaGroup()+
//        "&createOrg="+dcSupExamQuota.getCreateOrg());
//        MsgPushUtils.push(msg, dcSupExamQuota1.getId(), "DcSupExamQuota", dcSupExamQuota1.getCreateBy());

        //发送短信
        MsgDetail msgDetail = new MsgDetail();
        msgDetail.setSendid(UserUtils.getUser().getUserCode());
        msgDetail.setSubjectid(user.getUserCode());
        msgDetail.setMesg("您有一个关键指标报送被驳回，请及时登录系统查看!");
        lehandYzwPushTask.pushScoreShortMsg(msgDetail);
        dcSupBacklogService.add("目标考核","关键指标报送","关键指标报送审核驳回","提示信息"
                ,"您有一个关键指标报送被驳回，请及时查看!"
                ,"/a/quota/dcSupExamQuota?id="+dcSupExamQuota1.getId()+"&quotaGroup="+dcSupExamQuota.getQuotaGroup()+"&createOrg="+dcSupExamQuota.getCreateOrg(),dcSupExamQuota.getCreateOrg()
                ,dcSupExamQuota1.getExamId(),"exam_submit_key",user.getUserCode()
                ,"","");
        //关键指标审核处理exam_audit_key的待办
        dcSupBacklogService.doBacklog(dcSupExamQuota.getExamId(),"exam_audit_key",dcSupExamQuota.getCreateOrg());
    }

    /**
     * 单项/关键指标考核指标报送单位
     */
    public List<Map<String, String>> exameSendOrgListData(String createOrgName, String type, String examYear, String examId) {
        List<Map<String, String>> list=targetAuditDao.exameSendOrgListData(createOrgName, type, examYear, examId);
        List<Map<String, String>> mapList=new ArrayList<>();
        if(!list.isEmpty()){
            for (int i = 0; i < list.size(); i++) {
                if(list.get(i).get("submitstatus").contains(",")){
                    String[] s=list.get(i).get("submitstatus").split(",");
                    list.get(i).put("submitstatus",s[0]);
                }
            }
        }

        return list;
    }

    //单项/关键指标报送通知审核退回功能
    public void exameZBSendBack(String exameOrgs) {
        List<String> list = Arrays.asList(exameOrgs.split(","));
        targetAuditDao.exameZBSendBack(list);
    }

    //根据指标任务ID获取数据
    public DcSupExamQuota getDcSupExamQuotaById(DcSupExamQuota dcSupExamQuota) {
        return targetAuditDao.getDcSupExamQuotaById(dcSupExamQuota);
    }

    public List<DcSupExamQuotaInfo> dcSupExamScoreDataList(DcSupExamQuota dcSupExamQuota, String auditStatus) {
        //说明已经有审核通过的数据
        if ("2" == auditStatus) {
            dcSupExamQuota.setFileStatus("4");
        }
        return targetAuditDao.dcSupExamScoreDataList(dcSupExamQuota);
    }

    /**
     * 保存数据
     */
    @Transactional(readOnly = false,rollbackFor = Exception.class)
    public void saveAuditIndex(DcSupExamQuota dcSupExamQuota, String dcSupExamSumQuotaDtoListStr, String typeIndex) {
        try {
            String userCode = UserUtils.getUser().getUserCode();
            String userName = UserUtils.getUser().getUserName();
            dcSupExamQuota.setCreateBy(userCode);
            dcSupExamQuota.setCreateByName(userName);
            dcSupExamQuota.setUpdateBy(userCode);
            dcSupExamQuota.setUpdateByName(userName);
            String quotaId = IdGen.nextId();
            List<DcSupExamQuotaInfo> infoList = JSONArray.parseArray(dcSupExamSumQuotaDtoListStr, DcSupExamQuotaInfo.class);
            //三个表插数据  IdGen.nextId()  dc_sup_exam_quota  dc_sup_exam_quota_info  dc_sup_exam_quota_org
            //向考核任务指标表-报送-主表插入数据
            targetAuditDao.insertExamQuotaList(dcSupExamQuota, quotaId, typeIndex);
            //同步文件
            insertFile(dcSupExamQuota.getId(),quotaId);
            //获取考核任务指标表-指标信息表数据
            //获取考核任务指标表-被考核单位表数据
            createQuotaInfoList(dcSupExamQuota, infoList, quotaId);
            //关键指标审核处理exam_audit_key的待办
            dcSupBacklogService.doBacklog(dcSupExamQuota.getExamId(),"exam_audit_key",dcSupExamQuota.getCreateOrg());
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    /* //获取考核任务指标表-报送-主表数据
     private List<DcSupExamQuota> createQuotaList(DcSupExamQuota dcSupExamQuota,List<DcSupExamQuotaInfo> infoList) {
         List<DcSupExamQuota> dcSupExamQuotaList = new ArrayList<>();
         return dcSupExamQuotaList;
     }*/
    //获取考核任务指标表-指标信息表数据
    @Transactional(rollbackFor = Exception.class)
    public void createQuotaInfoList(DcSupExamQuota dcSupExamQuota, List<DcSupExamQuotaInfo> infoList, String quotaId) {
            Map<String, List<Object>> map = new HashMap<>();
            String quotaInfoId = "";
            //获取考核任务指标表-指标信息表数据
            List<DcSupExamQuotaInfo> dcSupExamQuotaInfoList = new ArrayList<>();
            DcSupExamQuotaInfo dcSupExamQuotaInfo = new DcSupExamQuotaInfo();
            //获取考核任务指标表-被考核单位表数据
            List<DcSupExamQuotaOrg> dcSupExamQuotaOrgList = new ArrayList<>();
            DcSupExamQuotaOrg dcSupExamQuotaOrg = new DcSupExamQuotaOrg();
            DcSupExamOrgSelect dcSupExamOrgSelect=new DcSupExamOrgSelect();
            if (!infoList.isEmpty()) {
                for (int i = 0; i < infoList.size(); i++) {
                    quotaInfoId = IdGen.nextId();
                    dcSupExamQuotaInfo = new DcSupExamQuotaInfo();
                    dcSupExamQuotaInfo.setId(quotaInfoId);
                    dcSupExamQuotaInfo.setQuotaId(quotaId);
                    dcSupExamQuotaInfo.setExamYear(dcSupExamQuota.getExamYear());
                    dcSupExamQuotaInfo.setQuotaType(infoList.get(i).getQuotaType());
                    dcSupExamQuotaInfo.setSortNum(infoList.get(i).getSortNum());
                    dcSupExamQuotaInfo.setQuotaContent(infoList.get(i).getQuotaContent());
                    dcSupExamQuotaInfo.setQuotaUnit(infoList.get(i).getQuotaUnit());
                    dcSupExamQuotaInfo.setQuotaWeight(infoList.get(i).getQuotaWeight());
                    dcSupExamQuotaInfo.setCurrentYaerGoal(infoList.get(i).getCurrentYaerGoal());
                    dcSupExamQuotaInfo.setLastYaerGoal(infoList.get(i).getLastYaerGoal());
                    dcSupExamQuotaInfo.setLastYearComplete(infoList.get(i).getLastYearComplete());
                    dcSupExamQuotaInfo.setFileFlag("2");
                    dcSupExamQuotaInfo.setQuotaClass(infoList.get(i).getQuotaClass());
                    dcSupExamQuotaInfo.setRemarks(infoList.get(i).getRemarks());
                    dcSupExamQuotaInfoList.add(dcSupExamQuotaInfo);
                    if( StringUtils.equals(dcSupExamQuota.getQuotaGroup(),"1")){
                        dcSupExamQuotaOrg = new DcSupExamQuotaOrg();
                        dcSupExamQuotaOrg.setId(IdGen.nextId());
                        dcSupExamQuotaOrg.setQuotaId(quotaId);
                        dcSupExamQuotaOrg.setQuotaInfoId(quotaInfoId);
                        dcSupExamQuotaOrg.setExameOrg(dcSupExamQuota.getCreateOrg());
                        dcSupExamQuotaOrg.setExameOrgName(dcSupExamQuota.getCreateOrgName());
                        dcSupExamOrgSelect.setOrgCode(dcSupExamQuota.getCreateOrg());
                        dcSupExamOrgSelect=dcSupExamOrgSelectService.getByOrgCode(dcSupExamOrgSelect);
                        dcSupExamQuotaOrg.setOrgType(dcSupExamOrgSelect.getOrgType());
                        dcSupExamQuotaOrg.setCurrentYaerGoal(infoList.get(i).getCurrentYaerGoal());
                        dcSupExamQuotaOrg.setQuotaUnit(infoList.get(i).getQuotaUnit());
                        dcSupExamQuotaOrg.setQuotaWeight(infoList.get(i).getQuotaWeight());
                        dcSupExamQuotaOrg.setLastYaerGoal(infoList.get(i).getLastYaerGoal());
                        dcSupExamQuotaOrg.setLastYearComplete(infoList.get(i).getLastYearComplete());
                        dcSupExamQuotaOrg.setAssessMethod(infoList.get(i).getAssessMethod());
                        dcSupExamQuotaOrg.setRemarks(infoList.get(i).getRemarks());
                        dcSupExamQuotaOrg.setCreateDate(new Date());
                        dcSupExamQuotaOrgList.add(dcSupExamQuotaOrg);
                    }

                }

                //向考核任务指标表-指标信息
                //String quotaInfoId = IdGen.nextId();
                targetAuditDao.insertExamQuotaInfoList(dcSupExamQuotaInfoList);
                //向考核任务指标表-被考核单位
                targetAuditDao.insertExamQuotaOrgList(dcSupExamQuotaOrgList);
            }
    }

    /**
     * 单项指标考核细则审核列表页面获取附件key
     */
    public DcSupExamQuota getDcSupExamXZQuotaById(String quotaGroup, String examId) {
        return targetAuditDao.getDcSupExamXZQuotaById(quotaGroup, examId);
    }

    public int dcSupExamScoreDataTotal2(DcSupExamQuota dcSupExamQuota) {
        return targetAuditDao.dcSupExamScoreDataTotal2(dcSupExamQuota);
    }
    public Boolean UrgeInformation(DcSupExamQuota dcSupExamQuota) {
        try {
            List<OfficeUser> officeUserList = dcSupTaskActionDao.getUserByOrg("EL_ORG",dcSupExamQuota.getCreateOrg());
            for (OfficeUser user: officeUserList) {
                //发送站内消息
                PcMsgContent msg = new PcMsgContent();
                msg.setTitle("提示信息");
                msg.setContent("请贵单位抓紧落实"+dcSupExamQuota.getRemarks()+"【"+dcSupExamQuota.getExamTitle()+"】该项任务，并及时给予反馈。");
                MsgPushUtils.push(msg, dcSupExamQuota.getExamTitle(), "DcSupTaskInfo", user.getUserCode());
                //发送短信
                MsgDetail msgDetail = new MsgDetail();
                msgDetail.setSendid(UserUtils.getUser().getUserCode());
                msgDetail.setSubjectid(user.getUserCode());
                msgDetail.setMesg("您有一个"+dcSupExamQuota.getRemarks()+"【"+dcSupExamQuota.getExamTitle()+"】,请及时登录系统查看");
                lehandYzwPushTask.pushScoreShortMsg(msgDetail);
            }
            return true;
        } catch (Exception e) {
            return false;
        }
    }
    public void cuibanGJ(cuibanDto cuiban) {
        String message = cuiban.getMessage();
        for (int i = 0; i < cuiban.getUserList().size(); i++) {
            cuiban.setPhone(cuiban.getUserList().get(i).getPhone());
            cuiban.setUserCode(cuiban.getUserList().get(i).getUserCode());
            PcMsgContent msg = new PcMsgContent();
            msg.setTitle("提示信息");
            msg.setContent(message);
            msg.addButton("指标审核", "/a/targetAudit/auditList");
            MsgPushUtils.push(msg, cuiban.getId(), "guanjianzhibiaoshenhecuiban", cuiban.getUserList().get(i).getUserCode());
            //发送易政网消息
            cuiban.setMessage(cuiban.getUserList().get(i).getName() + ","+cuiban.getMessage());
            //cuiban.setMessage(cuiban.getUserList().get(i).getName() + ",您有一个关键指标审核被催办,请及时登录系统查看");
            lehandYzwPushTask.pushYzwShortMsg2(cuiban);
        }
    }
    public void cuibanDX(cuibanDto cuiban) {
        String message = cuiban.getMessage();
        for (int i = 0; i < cuiban.getUserList().size(); i++) {
            cuiban.setPhone(cuiban.getUserList().get(i).getPhone());
            cuiban.setUserCode(cuiban.getUserList().get(i).getUserCode());
            PcMsgContent msg = new PcMsgContent();
            msg.setTitle("提示信息");
            msg.setContent(message);
            msg.addButton("指标审核", "/a/targetAudit/auditList");
            MsgPushUtils.push(msg, cuiban.getId(), "danxiangzhibiaoshenhecuiban", cuiban.getUserList().get(i).getUserCode());
            //发送易政网消息
            cuiban.setMessage(cuiban.getUserList().get(i).getName() + ","+cuiban.getMessage());
           // cuiban.setMessage(cuiban.getUserList().get(i).getName() + ",您有一个单项指标审核被催办,请及时登录系统查看");
            lehandYzwPushTask.pushYzwShortMsg2(cuiban);
        }
    }

    public void cuibanXZ(cuibanDto cuiban) {
        String message = cuiban.getMessage();
        for (int i = 0; i < cuiban.getUserList().size(); i++) {
            cuiban.setPhone(cuiban.getUserList().get(i).getPhone());
            cuiban.setUserCode(cuiban.getUserList().get(i).getUserCode());
            PcMsgContent msg = new PcMsgContent();
            msg.setTitle("提示信息");
            msg.setContent(message);
            msg.addButton("指标审核", "/a/targetAudit/auditList");
            MsgPushUtils.push(msg, cuiban.getId(), "xizeshenhecuiban", cuiban.getUserList().get(i).getUserCode());
            //发送易政网消息
            cuiban.setMessage(cuiban.getUserList().get(i).getName() + ","+cuiban.getMessage());
           // cuiban.setMessage(cuiban.getUserList().get(i).getName() + ",您有一个单细则审核被催办,请及时登录系统查看");
            lehandYzwPushTask.pushYzwShortMsg2(cuiban);
        }
    }

    @Transactional(rollbackFor = Exception.class)
    public DcSupExamQuota dxSubCopy(DcSupExamQuota dcSupExamQuota, Model model) {
            /**在审核单项指标时，查询报送的指标，插入dcSupExamQuota dcSupExamQuotaInfo dcSupExamQuotaOrg
             * 三个表中，便于页面的修改增加。页面操作审核通过时将dcSupExamQuota表中的submit_status改为4，若
             * 审核驳回，将刚插入的三表数据清空，等待下次再次审核重新添加。
             */
            DcSupExamQuota dse=this.dao.getDSEBySubmitStatus(dcSupExamQuota);
            if(dse==null){
                dcSupExamQuota=this.dao.getDcSupExamQuota(dcSupExamQuota);
                if(dcSupExamQuota==null){
                    return dse;
                }
                String dcSupExamQuotaId=dcSupExamQuota.getId();
                List<DcSupExamQuotaInfo> dcSupExamQuotaInfoList=this.dao.findDcSupExamQuotaInfoList(dcSupExamQuotaId);
                dcSupExamQuota.setId(null);
                //标识复制数据的状态 对应老数据的2  报送状态
                dcSupExamQuota.setSubmitStatus("5");
                dcSupExamQuota.setFormType("2");
                dcSupExamQuotaService.save(dcSupExamQuota);
                //同步文件
                insertFile(dcSupExamQuotaId,dcSupExamQuota.getId());

                if(!dcSupExamQuotaInfoList.isEmpty()){
                    for (DcSupExamQuotaInfo dcSupExamQuotaInfo:dcSupExamQuotaInfoList) {
                        List<DcSupExamQuotaOrg> dcSupExamQuotaOrgList=this.dao.findDcSupExamQuotaOrgList(dcSupExamQuotaInfo.getId());
                        dcSupExamQuotaInfo.setId(null);
                        dcSupExamQuotaInfo.setQuotaId(dcSupExamQuota.getId());
                        dcSupExamQuotaInfoService.insert(dcSupExamQuotaInfo);
                        DcSupExamOrgSelect dcSupExamOrgSelect=new DcSupExamOrgSelect();
                        if(!dcSupExamQuotaOrgList.isEmpty()){
                            for (DcSupExamQuotaOrg dcSupExamQuotaOrg:dcSupExamQuotaOrgList) {
                                dcSupExamQuotaOrg.setId(null);
                                dcSupExamQuotaOrg.setQuotaId(dcSupExamQuota.getId());
                                dcSupExamQuotaOrg.setQuotaInfoId(dcSupExamQuotaInfo.getId());
                                dcSupExamOrgSelect.setOrgCode(dcSupExamQuotaOrg.getExameOrg());
                                dcSupExamOrgSelect=dcSupExamOrgSelectService.getByOrgCode(dcSupExamOrgSelect);
                                dcSupExamQuotaOrg.setOrgType(dcSupExamOrgSelect.getOrgType());
                                dcSupExamQuotaOrgService.insert(dcSupExamQuotaOrg);
                            }
                        }
                    }
                }
            }else {
                return dse;
            }
            return dcSupExamQuota;
    }

    private void insertFile(String dcSupExamQuotaId,String newId) {
        FileUpload fileUpload = new FileUpload();
        fileUpload.setBizKey(dcSupExamQuotaId);
        List<FileUpload> fileUploadList=fileUploadService.findList(fileUpload);
        if(!fileUploadList.isEmpty()){
            for (FileUpload fu:fileUploadList) {
                fu.setId(null);
                fu.setBizKey(newId);
                fileUploadService.save(fu);
            }
        }

    }
    @Transactional(rollbackFor = Exception.class)
    public void exameSendDXBack(String dcSupExamQuotaId,String OldDcSupExamQuotaId,DcSupExamQuota dseq) {
        dseq.setSubmitStatus("3");
        //修改原上报指标 为退回
        dcSupExamQuotaService.save(dseq);
        DcSupExamQuota dcSupExamQuota=dcSupExamQuotaService.get(OldDcSupExamQuotaId);
        //删除复制的指标
        dcSupExamQuotaService.deleteDcSupExamQuotaId(dcSupExamQuotaId);
        //发送通知 去原指标上报人
//        PcMsgContent msg = new PcMsgContent();
//        msg.setTitle("提示信息");
        User user = UserUtils.get(dcSupExamQuota.getCreateBy());
//        msg.setContent("您有一个单项指标报送被驳回，请及时查看");
//        msg.addButton("报送", "/a/quota/dcSupExamQuota?id="+dcSupExamQuota.getId()+"&quotaGroup="+dcSupExamQuota.getQuotaGroup()+
//                "&createOrg="+dcSupExamQuota.getCreateOrg());
//        MsgPushUtils.push(msg, dcSupExamQuota.getId(), "DcSupExamQuota", dcSupExamQuota.getCreateBy());

        //发送短信
        MsgDetail msgDetail = new MsgDetail();
        msgDetail.setSendid(UserUtils.getUser().getUserCode());
        msgDetail.setSubjectid(user.getUserCode());
        msgDetail.setMesg("您有一个单项指标报送被驳回，请及时登录系统查看");
        lehandYzwPushTask.pushScoreShortMsg(msgDetail);
        dcSupBacklogService.add("目标考核","单项指标报送","单项指标报送审核驳回","提示信息"
                ,"您有一个单项指标报送被驳回，请及时查看!"
                ,"/a/quota/dcSupExamQuota?id="+dcSupExamQuota.getId()+"&quotaGroup="+dcSupExamQuota.getQuotaGroup()+"&createOrg="+dcSupExamQuota.getCreateOrg(),dcSupExamQuota.getCreateOrg()
                ,dcSupExamQuota.getExamId(),"exam_submit_dan",user.getUserCode()
                ,"","");
        //单项指标审核处理单项指标报送的待办
        dcSupBacklogService.doBacklog(dcSupExamQuota.getExamId(),"exam_audit_dan",dcSupExamQuota.getCreateOrg());
    }
    @Transactional(rollbackFor = Exception.class)
    public void dxsaveAuditIndex(String dcSupExamQuotaId,DcSupExamQuota dcSupExamQuota) {
        dcSupExamQuota.setSubmitStatus("2");
        dcSupExamQuotaService.save2(dcSupExamQuota);
        DcSupExamQuota dseq=new DcSupExamQuota();
        dseq.setSubmitStatus("4");
        dseq.setId(dcSupExamQuotaId);
        dcSupExamQuotaService.save(dseq);
        //单项指标审核处理单项指标报送的待办
        dcSupBacklogService.doBacklog(dcSupExamQuota.getExamId(),"exam_audit_dan",dcSupExamQuota.getCreateOrg());
    }
    @Transactional(rollbackFor = Exception.class)
    public String litteSendBack(DcSupExamSumQuotaInfo dcSupExamSumQuotaInfo) {
            String updateBy=null;
            String exameOrg=dcSupExamSumQuotaInfo.getExameOrg();
            List<DcSupExamSumQuotaInfo> dcSupExamSumQuotaInfoList=dcSupExamSumQuotaInfoService.findDcSupExamSumQuotaInfoList(dcSupExamSumQuotaInfo);
            for (DcSupExamSumQuotaInfo dsesqi:dcSupExamSumQuotaInfoList) {
                updateBy=dsesqi.getUpdateBy();
                dsesqi.setFileStatus("3");
                dcSupExamSumQuotaInfoService.save(dsesqi);
            }
//            //发送通知 去原指标上报人
//            PcMsgContent msg = new PcMsgContent();
//            msg.setTitle("提示信息");
            User user = UserUtils.get(updateBy);
//            msg.setContent("您有一个细则报送被驳回，请修改好重新报送");
//            msg.addButton("报送", "/a/quota/dcSupExamQuota/file?id=" + dcSupExamSumQuotaInfoList.get(0).getSumQuotaId() +"&quotaGroup="+dcSupExamSumQuotaInfoList.get(0).getQuotaGroup()+"&createOrg="+exameOrg+"&examYear="+dcSupExamSumQuotaInfoList.get(0).getExamYear());
//            MsgPushUtils.push(msg, dcSupExamSumQuotaInfoList.get(0).getSumQuotaId(), "DcSupExamQuota", updateBy);

            //发送短信
            MsgDetail msgDetail = new MsgDetail();
            msgDetail.setSendid(UserUtils.getUser().getUserCode());
            msgDetail.setSubjectid(user.getUserCode());
            msgDetail.setMesg("您有一个细则报送被驳回，请及时登录系统查看");
            lehandYzwPushTask.pushScoreShortMsg(msgDetail);
            DcSupExamSumQuotaInfo info = dao.getExamId(dcSupExamSumQuotaInfo.getSumQuotaId());
            dcSupBacklogService.add("目标考核","细则报送","单项指标细则报送审核驳回","提示信息"
                ,"您有一个细则报送被驳回，请及时查看!"
                ,"/a/quota/dcSupExamQuota/file?id=" + dcSupExamSumQuotaInfoList.get(0).getSumQuotaId() +"&quotaGroup="+dcSupExamSumQuotaInfoList.get(0).getQuotaGroup()+"&createOrg="+exameOrg+"&examYear="+dcSupExamSumQuotaInfoList.get(0).getExamYear(),exameOrg
                ,info.getExamId(),"exam_submit_xize",user.getUserCode()
                ,"","");
            //单项细则审核处理单项细则报送的待办
            dcSupBacklogService.doBacklog(info.getExamId(),"exam_audit_xize",exameOrg);
            return renderResult(Global.TRUE, text("退回成功！"));
    }
    @Transactional(rollbackFor = Exception.class)
    public String littleAuditIndex(DcSupExamSumQuotaInfo dcSupExamSumQuotaInfo) {
            List<DcSupExamSumQuotaInfo> dcSupExamSumQuotaInfoList=dcSupExamSumQuotaInfoService.findDcSupExamSumQuotaInfoList(dcSupExamSumQuotaInfo);
            for (DcSupExamSumQuotaInfo dsesqi:dcSupExamSumQuotaInfoList) {
                dsesqi.setFileStatus("4");
                dcSupExamSumQuotaInfoService.save(dsesqi);
            }
            DcSupExamSumQuotaInfo info = dao.getExamId(dcSupExamSumQuotaInfo.getSumQuotaId());
            //单项细则审核处理单项细则报送的待办
            dcSupBacklogService.doBacklog(info.getExamId(),"exam_audit_xize",dcSupExamSumQuotaInfo.getExameOrg());
            return renderResult(Global.TRUE, text("审核成功！"));
    }
}
